package com.ssh;

public class Rotate_48 {
	public static void main(String[] args) {
		int[][] matrix = {{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
		//int[][] matrix = {{},{},{},{}};
		rotate(matrix);
	}
	
	public static void rotate(int[][] matrix) {
			int n = matrix[0].length;
	        int m = n;
	        System.out.println("n="+n);
	        int a,b,c,d;
	        for (int i = 0,g = --m,l = n-1; i < l; i++,g--,l--) {
	        	for (int j = i,k = g; j < l; j++,k--) {
	            	a = matrix[i][j];
	            	System.out.println("a="+a);
	            	b = matrix[j][g];
	            	System.out.println("b="+b);
	            	c = matrix[g][k];
	            	System.out.println("c="+c);
	            	d = matrix[k][i];
	            	System.out.println("d="+d);
	            	matrix[i][j] = d;
	            	matrix[j][g] = a;
	            	matrix[g][k] = b;
	            	matrix[k][i] = c;
	            }
	        }
	        for (int i = 0; i < n; i++) {
	        	for (int j = 0; j < n; j++) {
	                System.out.print(matrix[i][j]);
	                System.out.print("\t");
	            }
	        	System.out.println();
	        }
    }
}
